package com.shiguiwu.springmybatis.app.convert;

import cn.hutool.core.date.DateUtil;
import com.shiguiwu.springmybatis.app.dto.UserDto;
import com.shiguiwu.springmybatis.app.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Optional;

/**
 * @description: 用户转化
 * @author: stone
 * @date: Created by 2023/4/22 23:42
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.app.convert
 */
@Mapper
public interface UserConvert {

    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    default UserDto copy(User user) {
        UserDto convert = convert(user);
        Optional.ofNullable(convert).ifPresent(u -> {
            u.setCreateTime(DateUtil.format(user.getCreateTime(), "yyyy-MM-dd hh:mm:ss"));
        });
        return convert;
    }

    UserDto convert(User user);
}
